<template>
	<view class="page-body">
		<view class="navbar " >
			<u-search  placeholder="输入关键字搜索" input-align="center" :show-action="false" v-model="keyword" @blur="loadData('refresh')" @clear="loadData('refresh')" ></u-search>
		</view>
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<view class="big_img p10">
			<!-- 空白页 -->
			<empty v-if="itemList.list.length === 0"></empty>
			<!-- 列表 -->
				<u-grid :col="2" class="u-grid" :border="false">
					<u-grid-item  v-for="(item,index) in itemList.list" :key="index" class="p0">
						<view class="img">
							<u-image width="100%"  mode="widthFix" :src="baseUrl+item.image"  @click="gotoPage('/pagesSchool/pages/school/hdPicInfo?hdPic='+item.image);"></u-image>
						</view>
						<view class="grid-text mt20">{{item.title}}</view>
					</u-grid-item>
				</u-grid>
			<uni-load-more :status="loadingType"></uni-load-more>
			</view>
		</scroll-view>
		<view class="goHome">
			<view class="share-btn">
				<image class="share-img" @click="showShareTip" src="/pagesA/static/images/share.png" mode=""></image>
			</view>
			<image class="go-home-btn" @click="gotoHomePage" src="/pagesB/static/channel/images/order_type02.png" mode=""></image>
		</view>
		<view class="tip-mask" v-if="shareTip" @click="showShareTip">
			<image class="img" src="/static/public/images/share/tip2.png" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	// import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	export default {
		components: {
			// uniLoadMore,
			empty
		},
		data() {
			return {
				baseUrl:this.config.cdnUrl,
				keyword: '',
				loadingType: 'more',
				param: {
					p: 0
				},
				itemList:{
					list:[]
				},
				shareTip:false
			}
		},
		onLoad() {
			this.loadData();
			let data = [];
			data.title = document.title;
			this.setWxShare(data);
		},
		onShow() {
		},
		onReady() {},
		methods: {
            gotoHomePage() {
                uni.navigateTo({
                    url: '/pages/index/index'
                })
            },
            gotoPage(url) {
                uni.navigateTo({
                    url: url
                })
            },
			showShareTip(){
				this.shareTip = !this.shareTip
			},
			setWxShare(data) {	
				var wxshare = require('./wxshare');
				this.$u.post('/member/api.users/getWxShare',{url:window.location.href}).then(res => {
					console.log(res);
					wxshare.config({
						debug: false,//是否打开调试
						appId: res.data.wxShare.appId, // 公众号的唯一标识  
						timestamp: res.data.wxShare.timestamp, // 生成签名的时间戳  
						nonceStr: res.data.wxShare.nonceStr, // ，生成签名的随机串  
						signature: res.data.wxShare.signature, // 签名  
						jsApiList: ['updateAppMessageShareData','updateTimelineShareData',]
					});
					wxshare.ready(function() {
						let links = window.location.href;
						let shareLink = ''
						if (links.indexOf('share_token') < 0){
							if (links.indexOf('?') > 0){
								shareLink = links + '&share_token=' + res.data.token; 
							}else{
								shareLink = links + '?share_token=' + res.data.token; 
							}
						}else{
							shareLink = links;
						}
						//分享给朋友
						wxshare.updateAppMessageShareData({
							title: data.title?data.title:'', // 分享标题  
							desc: data.desc?data.desc:'', // 分享描述  
							link: shareLink, // 当前页面链接  
							imgUrl: data.imgUrl?data.imgUrl:'', // 分享图标                                
							success: function() {//分享成功回调
								 
							},
							cancel: function() {//取消分享回调
							 
							}
						});
						//分享到朋友圈
						wxshare.updateTimelineShareData({
							title: data.title?data.title:'', // 分享标题
							desc: data.desc?data.desc:'', // 分享描述  
							link: shareLink, // 当前页面链接  
							imgUrl: data.imgUrl?data.imgUrl:'', // 分享图标                             
							success: function() {
							},
							cancel: function() {
							}
						});
					})
					
				})
			},
			
			loadData(source = 'add') {
				if (source == 'add' && this.loadingType == 'nomore') {
					return;
				}
				if (source === 'refresh') {
					this.param.p = 0;
					this.itemList.list = [];
				}
				this.param.keyword = this.keyword;
				this.param.p++;
				this.$u.post('school/api.hd_pic/getList', this.param).then(res => {
					this.itemList.list = this.itemList.list.concat(res.data.list);
					//loaded新字段用于表示数据加载完毕，如果为空可以显示空白页
					this.$set(this.itemList, 'loaded', true);
					//判断是否还有下一页，有是more  没有是nomore
					this.loadingType = this.param.p == res.data.page_count ? 'nomore' : 'more';
					
				})
			},
		}
	}
</script>

<style lang="scss">
	.list-scroll-content {
		position: relative;
		height: calc(100vh - 80rpx);
	}
	.big_img{
		.u-grid-item{
			border: 10rpx solid #FFFFFF;
			.img{
				width: 100%;
				height: 580rpx;
				overflow: hidden;
			}
		}
	}
</style>
